<template>
    <div id="pwd">
        <el-input show-password v-model="upForm.password" placeholder="请输入当前密码"></el-input>
        <br><br>
        <el-input show-password v-model="upForm.newPassword" placeholder="输入新密码"></el-input>
        <br><br>
        <el-input show-password v-model="upForm.rePassword" placeholder="再输入一次">

        </el-input>
        <br><br>
        <el-button style="width: 100%" type="primary" @click="submit()">提交</el-button>
    </div>


</template>

<script>
    import {pwdChange} from "../../network/admin"
    export default {
        name:'pwdChange',
        data(){
            return{
                upForm:{
                    password:'',
                    newPassword:'',
                    rePassword:''
                }

            }
        },
        methods:{
            submit(){
                if(this.upForm.newPassword!==this.upForm.rePassword){
                       this.$message.warning("两次密码输入不一样")
                }else{
                  if(this.upForm.newPassword=="" || this.upForm.newPassword==null){
                     this.$message.warning("新密码不允许为空");
                  }else{
                    pwdChange(this.upForm)
                        .then(res=>{
                          console.log(res);
                          if(res.data.code==100){
                            this.$message.success(res.data.data)
                            this.$store.dispatch("user/logout");
                          }else {
                            this.$message.warning("修改失败")
                          }
                        })
                  }
                }
            }
        }
    }
</script>

<style>
    #pwd{
        width: 33%;
        margin: 120px auto 0;
    }
</style>
